<?php   
class ServicesController extends Controller {
    
    public function actionIndex(){
        $url = new Url();
        $date = date('Y-m-d',time());
        $data = array();        
        $page_num = isset($_GET['page']) ? intval($_GET ['page']):1;            
        $province_id = isset($_GET['tinh'])?$_GET['tinh']:"";
        $keyword = isset($_GET['keyword'])?$_GET['keyword']:"";
        $type_keyword = isset($_GET['type_keyword'])?$_GET['type_keyword']:"";
        $service_id = isset($_GET['service_id'])?$_GET['service_id']:"";
        $tungay = isset($_GET['tungay'])?$_GET['tungay']:"";
        $denngay = isset($_GET['denngay'])?$_GET['denngay']:"";
        $rows_per_page = 20;         
        $count = AdminBill::countBill($province_id,$keyword,$type_keyword,$service_id,$tungay,$denngay);                   
        if($count % $rows_per_page == 0){
            $totalpage = floor($count/$rows_per_page);
        } else{
            $totalpage = floor($count/$rows_per_page) + 1;                             
        }
        $begin      = ($page_num - 1)*$rows_per_page;
        $end        = $rows_per_page;      
        
          
        $provice = Province::getAllRows(); 
        $data = AdminBill::searchBill($province_id,$keyword,$type_keyword,$service_id,$tungay,$denngay,$begin,$end);        
        $get_url    = "?tinh=".$province_id."&keyword=".$keyword."&type_keyword=".$type_keyword."&service_id=".$service_id."&tungay=".$tungay."&denngay=".$denngay;
        $page       = Paging::showPageNavigation($page_num,$totalpage,$url->createUrl('services/index').$get_url."&");
        
        $this->render('index',array("provice"=>$provice,"data"=>$data,"page"=>$page,"begin"=>$begin));
    }
        
}